#include "ros/ros.h"
#include "std_msgs/String.h"

#include <sstream>
int main(int argc, char **argv)
{
    ros::init(argc, argv, "talker");
    //为进程的节点创建句柄，执行节点的初始化
    ros::NodeHandle n;

    //topic:"chatter", type: std_msgs/String
    ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);
    //指定ros程序循环运行的频率：10hz
    ros::Rate loop_rate(10);

    int count = 0;

    while(ros::ok())
    {
        std_msgs::String msg;
        std::stringstream ss;
        ss<<"Hello ROS id:"<<count;
        msg.data = ss.str();
        //ROS_INFO是print的代替
        ROS_INFO("%s",msg.data.c_str());
        //发送消息
        chatter_pub.publish(msg);
        //调用以添加订阅
        ros::spinOnce();
        //在剩余时间里休眠以达到发布频率
        loop_rate.sleep();
        ++count;
    }
    return 0;
}